package com.zzc.mapper;

import com.zzc.domain.Product;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Zzc
 * @since 2020-08-05
 */

@Repository
public interface ProductMapper extends BaseMapper<Product> {

    @Update("update product set product_inventory = product_inventory-1 where product_id = #{productId} and product_inventory > 0")
    int updateInventory(@Param("productId") int productId);

    @Select("select product_inventory from product where product_id = #{productId}")
    int getProductInventory(@Param("productId") int productId);
}
